﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BSCMFF.Core.DataAccessLayer;

namespace BSCMFF.Web.UserControls
{
    public partial class SurveyQuestionControl : System.Web.UI.UserControl
    {
        private Survey_Question _sq;
        public Survey_Question SQ
        {
            get
            {
                return _sq;
            }
            set
            {
                _sq = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (SQ != null)
            {
                LabelQuestion.Text = SQ.Question;
                LoadAnswers(SQ.ID);
            }
        }

        private void LoadAnswers(int question_ID)
        {
            BSCEntities context = new BSCEntities();
            List<Survey_Answer> answers = (from answer in context.Survey_Answer
                                           where answer.Question_FK == question_ID
                                           select answer).ToList();
            foreach (Survey_Answer a in answers)
            {
                ListItem li = new ListItem();
                //li.
                li.Text = a.Answer;
                li.Value = a.ID.ToString();

                RadioButtonListAnswers.Items.Add(li);
            }
        }

        public int? GetSelectedAnswerID()
        {
            if (RadioButtonListAnswers.SelectedValue != "")
            {
                return Int32.Parse(RadioButtonListAnswers.SelectedValue);
            }
            else return null;
        }

        //protected override object SaveViewState()
        //{
        //    return null;
        //}
    }
}